<?php

namespace app\admin\model;

use think\Cache;
use think\Model;

class Teachers extends Model
{
    // 表名
    protected $name = 'teachers';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'shen_text','shi_text','xian_text'
    ];

    public function getPayTextAttr($value, $data)
    {
        $value = $value ? $value : $data['pay'];
        $list = $this->getPayList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getShenTextAttr($value, $data)
    {
        $value = $value ? $value : $data['shen'];
        $list = $this->getProvinceOrderList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getShiTextAttr($value, $data)
    {
        $value = $value ? $value : $data['shi'];
        $list = $this->getProvinceOrderList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getXianTextAttr($value, $data)
    {
        $value = $value ? $value : $data['xian'];
        $list = $this->getProvinceOrderList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getProvinceOrderList()
    {
        if(!$list = Cache::get('arealist'))
        {
            $area = Area::field('id,name')->select();
            $area = collection($area)->toArray();
            $list = array_column($area,'name','id');
            Cache::set('areaList',$list,0);//设置0永久缓存不过期
        }
        return $list;
    }

    







}
